<template>


	<view class="help_popup">
		<view class="popup_title" @click="showPlayVideo">
			{{help.type==1?"关注公众号":help.type==2?"加好友":
				help.type==3?"观看视频":help.type==4?"邀请好友":""
				}}
		</view>
		<view class="popup_content" v-if="help.type==1">
			<image @longpress="handleLongPress" class="img" :src="domain+help.data.photo"></image>
			<view class="btn">
				{{help.data.text?help.data.text:"点击长按二维码关注公众号"}}
			</view>
		</view>
		<view class="popup_content" v-if="help.type==2">
			<view v-if="help.data.wxnumber" class="wx_box">
				<text class="left">微信号:</text><text class="mid">{{help.data.wxnumber}}</text><text
					@click="copyText(help.data.wxnumber)" class="right">点击复制</text>
			</view>
			<image v-if="help.data.photo" @longpress="handleLongPress" class="img" :src="domain+help.data.photo">
			</image>
			<view class="btn">
				{{help.data.text?help.data.text:help.data.photo?"点击长按二维码添加好友":"点击复制微信号添加好友"}}
			</view>
		</view>
		<view class="popup_content" v-if="help.type==3">
			<view>观看视频</view>
			<view>随机加1-10助力值</view>

			<view class="btn" @click="showPlayVideo">点击观看</view>

		</view>
		<view class="popup_content" v-if="help.type==4">
			<view>邀请好友帮忙助力</view>
			<view>随机加1-10助力值</view>
			<button open-type="share" class="btn" @click="inviteFriend">点击邀请</button>
		</view>
		<playVideo @changShow="changShow" :help="help" :videoSrc="videoSrc" :showVideo="showVideo"></playVideo>
	</view>


</template>
<script>
	import playVideo from "./playVideo"
	export default {
		components: {
			playVideo
		},
		data() {
			return {
				domain: uni.$http.baseUrl + "/",
				videoSrc: "",
				showVideo: ""
			}
		},
		props: {
			help: {
				type: Object,
				default: () => ({})
			}

		},
		methods: {
			copyText(text) {
				uni.setClipboardData({
					data: text,
					success() {
						uni.showToast({
							title: '复制成功',
							icon: 'success'
						})
					}
				})
			},
			changShow(val) {
				this.showVideo = false;
			},
			showPlayVideo() {
				this.showVideo = true;
			},
			inviteFriend() {
				uni.share({
					title: '邀请好友',
					content: '快来一起玩吧！',
					success: function() {
						console.log('分享成功');
					},
					fail: function(err) {
						console.log('分享失败：' + JSON.stringify(err));
					}
				});

			},
			showVideoModal() {
				uni.showModal({
					title: '视频播放',
					content: '<video src="/static/video.mp4"></video>',
					showCancel: false,
					confirmText: '关闭'
				});
			},
			addWechatFriend() {
				uni.showModal({
					title: '添加微信好友',
					content: '是否添加微信好友？',
					success: (res) => {
						if (res.confirm) {
							uni.showToast({
								title: '已发送好友请求',
								icon: 'success'
							});
							// 调用微信添加好友的 API
							uni.addPhoneContact({
								firstName: '微信好友',
								weChatNumber: '微信号',
								success: () => {
									uni.showToast({
										title: '添加成功',
										icon: 'success'
									});
								},
								fail: () => {
									uni.showToast({
										title: '添加失败',
										icon: 'none'
									});
								}
							});
						}
					}
				});
			},
			handleLongPress() {
				uni.scanCode({
					success: (res) => {
						const result = res.result;
						// 判断识别结果是否为公众号二维码
						if (result.startsWith('gh_')) {
							// 提取公众号标识（通常是以gh_开头的字符串）
							const weChatId = result.substring(3);
							// 跳转到公众号页面
							uni.navigateToMiniProgram({
								appId: '公众号的appid',
								path: '公众号的路径',
								extraData: {
									wechatId: wechatId
								},
								success(res) {
									// 跳转成功的回调
								},
								fail(err) {
									// 跳转失败的回调
								}
							});
						}
					},
					fail: (err) => {
						console.log(err);
					}
				});
			},


			close() {
				this.$refs.popup.close()
			},
			openPopup() {
				this.$refs.popup.open()
			}
		}
	}
</script>
<style lang="scss" scoped>
	.help_popup {
		background: #fff;
		border-radius: 32rpx 32rpx 0px 0px;

		.popup_title {
			width: 750rpx;
			height: 91rpx;
			background: linear-gradient(316deg, #356AFA 0%, #34B8FD 100%);
			border-radius: 32rpx 32rpx 0px 0px;
			color: #fff;
			font-size: 34rpx;
			text-align: center;
			line-height: 91rpx;
			transform: translateY(-32rpx)
		}

		.popup_content {
			background: #fff;
			color: #555;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			line-height: 42rpx;

			.wx_box {
				font-size: 30rpx;
				line-height: 30rpx;
				margin: 20rpx 100rpx;
				display: flex;


				.mid {
					flex: 1;
					color: #000;
					width: 300rpx;
					font-weight: bolder;
					margin: 0 15rpx;
				}
			}

			.img {
				margin: 20rpx 0 50rpx 0;
			}

			.btn {
				width: 452rpx;
				height: 56rpx;
				background: #3392FA;
				border-radius: 66rpx;
				font-size: 28rpx;
				color: #fff;
				line-height: 56rpx;
				text-align: center;
				margin-bottom: 50rpx;
				margin-top: 30rpx;
			}
		}
	}
</style>